all: server client

server: server.cpp
	@echo -e "\nCompiling server and caching:\n"
	g++ -Wall -o server server.cpp caching.cpp

client: client.cpp
	@echo -e "\nCompiling client:\n"
	g++ -Wall -o client client.cpp

caching: caching.cpp
	#
	# Note: the following code compiles caching.cpp, which doesn't have a main.
	# Obviously, g++ (and any other c++ compiler, for that matter) doesn't want a file with no main.
	# To workaround this, I check to see if the special cpp file "tmpMain.cpp" exists.
	# If it doesn't, I create it by echoing the text "int main() {\n return 0; \n}" into it.
	# Now caching.cpp can be compiled with tmpMain.cpp successfully, since a main() exists.
	#
	@echo -e "\nCompiling caching:\n"
	@if [ ! -e tmpMain.cpp ]; then \
	echo -e "Writing new temp file with a main() in it so caching.cpp will compile." ; \
	echo -e "int main() {\n  return 0;\n}\n" > tmpMain.cpp ; \
	fi
	g++ -Wall tmpMain.cpp caching.cpp


clean:
	rm -f server
	rm -f client
	rm -f tmpMain.cpp
	rm -f *.out
	rm -f *~
